package com.slkj.shilixiaoyuanapp.ui.teacher.tool.Purchase;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.data.UserRequest;
import com.slkj.shilixiaoyuanapp.entity.ToolPurchaseDetailEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.common.ChosePeopleActivity;
import com.slkj.shilixiaoyuanapp.view.NumberEditText;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;
import com.tkk.api.RxEventProcessor;

import butterknife.BindView;
import butterknife.OnClick;

@ActivityInfo(layout = R.layout.activity_purchase_dsp, title = "待审批 ")
public class PurchaseDspActivity extends BaseActivity {
    @InjectParam
    int id;
    @InjectParam
    ToolPurchaseDetailEntity data;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_menoy)
    TextView tvMenoy;
    @BindView(R.id.tv_now_day_time)
    TextView tvNowDayTime;
    @BindView(R.id.edit_name)
    EditText editName;
    @BindView(R.id.layout_chose_type)
    RelativeLayout layoutChoseType;
    @BindView(R.id.edit_num)
    EditText editNum;
    @BindView(R.id.edit_price)
    EditText editPrice;
    @BindView(R.id.tv_bm)
    TextView tvBm;
    @BindView(R.id.layoout_bumen)
    RelativeLayout layooutBumen;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.layout_chose_time)
    RelativeLayout layoutChoseTime;
    @BindView(R.id.edit_content)
    NumberEditText editContent;
    @BindView(R.id.tv_spr)
    TextView tvSpr;
    @BindView(R.id.tv_cb)
    TextView tvCb;
    @BindView(R.id.iv_select_spr)
    ImageView iv_select_spr;
    public static final String tag = "PurchaseDspActivity";

    @Override
    protected void init() {
        PurchaseDspActivity__JumpCenter.bind(this);
        RxEventProcessor.get().bind(this);
        tvUserName.setText(data.getName());
        tvNowDayTime.setText(data.getIntime());
        editName.setText(data.getGoods());
        editContent.setText(data.getBody());
        tvBm.setText(data.getDepartment().getdName());
        editContent.setText(data.getBody());
        tvSpr.setText(ChosePeopleActivity.getPeoplesInfos(data.getAuditor()));
        editNum.setText(String.valueOf(data.getNum()));
        editPrice.setText(String.valueOf(data.getMoney()));
        tvTime.setText(data.getHoursOfUse());
        try{
            int num = Integer.valueOf(editNum.getText().toString());
            double price = Double.valueOf(editPrice.getText().toString());
            tvMenoy.setText(String.valueOf(num*price));
        }catch (Exception e){
            tvMenoy.setText(String.valueOf(""));

        }
        tvCb.setEnabled(!data.isUrge());

        iv_select_spr.setVisibility(View.GONE);
    }
    /**
     * 删除。
     */
    @OnClick(R.id.tv_cx)
    void delete() {
        HttpHeper.get().toolService()
                .toolDelete("Evection/deleteByIdAuditEvection.do", id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(PurchaseDspActivity.this,data);
                        finish();
                    }
                });
    }

    /**
     * 催办
     */
    @OnClick(R.id.tv_cb)
    void cb() {
        HttpHeper.get().toolService()
                .cb(ChosePeopleActivity.getIdList(data.getAuditor()).toString(),id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(PurchaseDspActivity.this,data);
                        tvCb.setEnabled(false);

                    }
                });
    }
}
